<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title>Movimento</title>
            <link rel="stylesheet" type="text/css" href="/globalimage2/faces/jsfcrud.css" /><%@ include file="/WEB-INF/jspf/AjaxScripts.jspf" %><script type="text/javascript" src="/globalimage2/faces/jsfcrud.js"></script>
        </head>
        <body>
            <%@include file="../../WEB-INF/jspf/header/head.jspf"%>
            <div style="float:left">
                <%@include file="../../WEB-INF/jspf/header/menuDinamico.jspf"%>
            </div>
            <div id="div_content">
                <div class="bgContentTable">
                    <div class="titleTable"><h3>Entrada & Sa&iacute;da</h3></div><br />
                    <h:form styleClass="jsfcrud_list_form">

                        <h:panelGroup id="messagePanel" layout="block">
                            <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                        </h:panelGroup>
                        
                        &nbsp;<h:outputText value="Período: "/>
                        <h:selectOneMenu value="#{entradaSaida.dateInicio.dia}" onchange="submit();">
                            <f:selectItems value="#{utilController.arrayDias}"></f:selectItems>
                        </h:selectOneMenu>
                        <h:selectOneMenu value="#{entradaSaida.dateInicio.mes}" onchange="submit();">
                            <f:selectItems value="#{utilController.arrayMeses}"></f:selectItems>
                        </h:selectOneMenu>
                        <h:selectOneMenu value="#{entradaSaida.dateInicio.ano}" onchange="submit();">
                            <f:selectItems value="#{utilController.arrayAnos}"></f:selectItems>
                        </h:selectOneMenu>

                        <h:outputText value=" ... "/>

                        <h:selectOneMenu value="#{entradaSaida.dateFim.dia}" onchange="submit();">
                            <f:selectItems value="#{utilController.arrayDias}"></f:selectItems>
                        </h:selectOneMenu>
                        <h:selectOneMenu value="#{entradaSaida.dateFim.mes}" onchange="submit();">
                            <f:selectItems value="#{utilController.arrayMeses}"></f:selectItems>
                        </h:selectOneMenu>
                        <h:selectOneMenu value="#{entradaSaida.dateFim.ano}" onchange="submit();">
                            <f:selectItems value="#{utilController.arrayAnosMaisDez}"></f:selectItems>
                        </h:selectOneMenu>
                        &nbsp;
                        <h:selectBooleanCheckbox value="#{entradaSaida.buscaVenda}" title="Venda" onchange="submit();"/>
                        <h:outputText value="Venda"/>
                        <h:selectBooleanCheckbox value="#{entradaSaida.buscaCompra}" title="Compra" onchange="submit();"/>
                        <h:outputText value="Compra"/>
                        <h:selectBooleanCheckbox value="#{entradaSaida.buscaManutencao}" title="Manutenção" onchange="submit();"/>
                        <h:outputText value="Manutenção"/>
                        <h:selectBooleanCheckbox value="#{entradaSaida.buscaFolha}" title="Folha de pagamento" onchange="submit();"/>
                        <h:outputText value="Folha de pagamento"/>
                        &nbsp;
                        <h:commandButton action="#{entradaSaida.buscar}" value="Ir"/>
                        &nbsp;&nbsp;

                        <h:outputText escape="false" value="<br/><br/>Não foi encontrado registros<br />" rendered="#{empty entradaSaida.entradaSaidaItems}" />
                        <h:panelGroup rendered="#{not empty entradaSaida.entradaSaidaItems}">

                            <div style="text-align:right;width:450px;float:right;margin-right:7px;">
                                <h:outputText value="  Item #{entradaSaida.pagingInfo.firstItem + 1}..#{entradaSaida.pagingInfo.lastItem} de #{entradaSaida.pagingInfo.itemCount}"/>&nbsp;
                                <h:commandLink action="#{entradaSaida.prev}" value="Anterior #{entradaSaida.pagingInfo.batchSize}" rendered="#{entradaSaida.pagingInfo.firstItem >= entradaSaida.pagingInfo.batchSize}"/>&nbsp;
                                <h:commandLink action="#{entradaSaida.next}" value="Próximo #{entradaSaida.pagingInfo.batchSize}" rendered="#{entradaSaida.pagingInfo.lastItem + entradaSaida.pagingInfo.batchSize <= entradaSaida.pagingInfo.itemCount}"/>&nbsp;
                                <h:commandLink action="#{entradaSaida.next}" value="Restantes #{entradaSaida.pagingInfo.itemCount - entradaSaida.pagingInfo.lastItem}"
                                               rendered="#{entradaSaida.pagingInfo.lastItem < entradaSaida.pagingInfo.itemCount && entradaSaida.pagingInfo.lastItem + entradaSaida.pagingInfo.batchSize > entradaSaida.pagingInfo.itemCount}"/>
                            </div>

                            <c:if test="${empty entradaSaida.entradaSaidaItems}">
                                <br/>
                                <h:outputText value="Não foi encontradas entrdas para essa margem de tempo" style="color: green"/>

                            </c:if>


                            <h:dataTable value="#{entradaSaida.entradaSaidaItems}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px; width: 99%; margin-left: 5px;">

                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Beneficiaria"/>
                                    </f:facet>
                                    <h:commandLink value="#{item.resumoDinamico}" action="#{entradaSaida.detailSetup}">
                                        <f:param name="jsfcrud.currentEntradaSaida" value="#{jsfcrud_class['entidade.controller.JSF.util.JsfUtil'].jsfcrud_method['getAsConvertedString'][item][entradaSaida.converter].jsfcrud_invoke}"/>
                                    </h:commandLink>
                                </h:column>

                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Data operação"/>
                                    </f:facet>
                                    <div align="center">
                                        <h:outputText value="#{item.dataOperacao}">
                                            <f:convertDateTime pattern="dd / MM / yyyy" />
                                        </h:outputText>
                                    </div>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Vencimento"/>
                                    </f:facet>
                                    <div align="center">
                                        <h:outputText value="#{item.dataVencimento}">
                                            <f:convertDateTime pattern="dd / MM / yyyy" />
                                        </h:outputText>
                                    </div>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Parcela"/>
                                    </f:facet>
                                    <div align="center">
                                        <h:outputText value="#{item.parcelaAtual} de #{item.quantidadeParcela}"/>
                                    </div>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Total"/>
                                    </f:facet>
                                    <div align="right">
                                        <h:outputText value="#{item.totalOperacao}">
                                            <f:convertNumber type="currency"/>
                                        </h:outputText>
                                    </div>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="Valor parcela"/>
                                    </f:facet>
                                    <div align="right">
                                        <h:outputText value="#{item.valor}" style="color:blue" rendered="#{item.isValorPositivo}">
                                            <f:convertNumber type="currency"/>
                                        </h:outputText>
                                        <h:outputText value="#{item.valor}" style="color:red" rendered="#{!item.isValorPositivo}">
                                            <f:convertNumber type="currency"/>
                                        </h:outputText>

                                    </div>
                                </h:column>
                            </h:dataTable>
                        </h:panelGroup>
                        &nbsp;&nbsp;
                        <h:panelGrid columns="4">
                            <h:panelGrid columns="2" border="1">
                                <h:outputText value="Vendas: " />
                                <h:outputText value="#{entradaSaida.totalVenda}">
                                    <f:convertNumber type="currency" />
                                </h:outputText>
                            </h:panelGrid>

                            <h:panelGrid columns="2" border="1">
                                <h:outputText value="Folhas de pagamentos: " />
                                <h:outputText value="0.0" >
                                    <f:convertNumber type="currency" />
                                </h:outputText>
                            </h:panelGrid>

                            <h:panelGrid columns="2" border="1">
                                <h:outputText value="Compras: " />
                                <h:outputText value="#{entradaSaida.totalCompra}" >
                                    <f:convertNumber type="currency" />
                                </h:outputText>
                            </h:panelGrid>

                            <h:panelGrid columns="2" border="1">
                                <h:outputText value="Manutenções: " />
                                <h:outputText value="0.0" >
                                    <f:convertNumber type="currency" />
                                </h:outputText>
                            </h:panelGrid>
                        </h:panelGrid>

                        <br/>&nbsp;
                        <h:outputText value="Total geral: " />
                        <h:outputText value="#{entradaSaida.totalEntradaSaida}">
                            <f:convertNumber type="currency" />
                        </h:outputText>

                    </h:form>
                </div>
            </div>
        </body>
    </html>
</f:view>
